<template>
  <van-picker
    title="更改性别"
    show-toolbar
    :columns="columns"
    @confirm="onConfirm"
    @cancel="$emit('close')"
    :default-index="value"
  />
</template>

<script>
import { setUserInfo } from '@/api/user.js'
import { Toast } from 'vant'
export default {
  props: {
    value: {
      type: Number
    }
  },
  data () {
    return {
      columns: ['男', '女']
    }
  },

  created () {},

  methods: {
    async onConfirm (value, index) {
      Toast.loading({
        message: '加载中...',
        forbidClick: true,
        duration: 0
      })
      try {
        await setUserInfo({
          gender: index
        })
        Toast.success()
        this.$emit('input', index)
        this.$emit('close')
      } catch (err) {
        Toast.fail()
      }
    }
  }
}
</script>

<style scoped lang="less"></style>
